/*
 *  Copyright 2010 Wesley Gooch, Ryan Nix, Cody Wenzel.
 *  Montana State University - Spring Semester 2010
 *  Computer Science 450 - Compilers
 *  Project: Micro-Pascal Compiler
 */
package msu.compiler.scanner.fsas;

import msu.compiler.scanner.Token;
import msu.compiler.scanner.Tokenizer;

/**
 *
 * @author Cody Wenzel
 */
public class StringLiteralFSA extends FSA {

    public StringLiteralFSA(Tokenizer tokenizer) {
        super(tokenizer);
        initializeStates(3);
    }

    public void execute() {
        Character currentChar;
        while (notFinished()) {
            currentChar = getCurrentChar();
            switch (getCurrentState()) {
                case 0:
                    if (currentChar == '\'') {
                        setCurrentState("s1");
                        peekAhead();
                    } else {
                        fail();
                    }
                    break;
                case 1:
                    if (currentChar == '\'') {
                        setAcceptState("s2", Token.MP_STRING_LIT);
                        peekAhead();
                    } else if (Tokenizer.isEndOfLine(currentChar) || (int)currentChar == -1) {
                        handleError(Token.MP_RUN_STRING);
                    } else {
                        setCurrentState("s1");
                        peekAhead();
                    }
                    break;
                case 2:
                    if(currentChar == '\'') {
                        setCurrentState("s1");
                        peekAhead();
                    } else {
                        fail();
                    }
                    break;
                default:
                    fail();
                    break;
            }
        }
    }
}
